import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state:{
        cartList:[],
        checkAll:false
    },
    mutations:{
        addCart(state,payload){
            payload.goodsWeight ++
            let goods = state.cartList.find(val => val.goodsId === payload.goodsId)
            if(!goods){
                state.cartList.push(payload)
            }
        },
        subCart(state,payload){
            payload.goodsWeight --
            if(payload.goodsWeight == 0){
                let index = state.cartList.findIndex(item => item.goodsId === payload.goodsId)
                state.cartList.splice(index,1)
            }
        },
        changeFlag(state,payload){

        },
        changeAll(state){
            state.cartList.forEach(val)
            state.checkAll = !state.checkAll
        }
    },
    actions:{
        
    },
    getters:{

    }
})
